package com.google.gwt.sample.dynatablerf.client.home.presenter;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.sample.dynatablerf.client.home.events.GoToProdutoCrudViewEvent;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;

public class MainPresenter {

	private Display display;
	private EventBus eventBus;
	
	public interface Display extends IsWidget {
		
		HasWidgets getContainer();

		HasClickHandlers getClientes();

		HasClickHandlers getPedidos();

		HasClickHandlers getCategorias();

		HasClickHandlers getProdutos();
		
	}
	
	public MainPresenter(Display display,EventBus event){
		this.display = display;
		this.eventBus = event;
		bind();
		
	}

	private void bind() {
		display.getProdutos().addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				eventBus.fireEvent(new GoToProdutoCrudViewEvent(display.getContainer()));
				
				
			}
		});
		
	}
	
	public void go(HasWidgets hasWidgets) {
		hasWidgets.clear();
		hasWidgets.add(display.asWidget());
//		Scheduler.get().scheduleDeferred(new ScheduledCommand() {
//
//			@Override
//			public void execute() {
//				eventBus.fireEvent(new GoToCategoriaViewEvent(display
//						.getContainer(), null));
//			}
//		});
	}
	
}
